import json
from calc_loss_001 import calculate_loss



# 使用示例
if __name__ == "__main__":
    try:
        loss_calc_payload = {
            "stockNo": "002945",  # 股票代码
            "stockName": "华林证券",  # 股票名称
            "brokerName": "中信证券",  # 券商名称
            "stockBroker": "600030"  # 券商代码
        }

        transactions = [
            {
                "stockNo": "002945",
                "operationTime": "2023-02-27",
                "direction": "buy",
                "price": 14.30,
                "qty": 500,
                "amount": 7150
            },
            {
                "stockNo": "002945",
                "operationTime": "2023-03-24",
                "direction": "sell",
                "price": 12.00,
                "qty": 500,
                "amount": 6000
            }
        ]

        results = calculate_loss(loss_calc_payload=loss_calc_payload, transactions=transactions)
        print("盈亏试算流程完成，结果：")
        for step, result in results.items():
            print(f"\n{step}:", json.dumps(result, indent=2, ensure_ascii=False))
    except Exception as e:
        print(f"执行过程中出现错误: {str(e)}")

"""
# FIXME 测试失败，损失金额错误
测算结果：status=10 成功，预期损失金额=994.8958  实际损失金额estimate_loss_ammount=1150.000

SELECT * from stock_loss_caculation where id=885422821293953024;
SELECT * from stock_loss_caculation_detail where loss_id = 885422821293953024;
"""
